import Mock from 'mockjs'
import { param2Obj } from '@/utils'

const List = []
const count = 100
const mapList = []
const mcount = 3
const mapDataList = []
const mdcount = 10

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: '@increment',
    qid: '@word(3, 5)',
    'type|1': ['line', 'bar'],
    title: '@ctitle(3, 10)',
    serTrends: [{
      timePoint: '@time("HH:mm:ss")',
      reqCnt: '@float(1, 100, 1, 3)'
    }, {
      timePoint: '@time("HH:mm:ss")',
      reqCnt: '@float(1, 100, 1, 3)'
    }, {
      timePoint: '@time("HH:mm:ss")',
      reqCnt: '@float(1, 100, 1, 3)'
    }]
  }))
}

for (let i = 0; i < mcount; i++) {
  mapList.push(Mock.mock({
    id: '@increment',
    qid: '@word(3, 5)',
    title: '@ctitle(3, 10)',
    serTrends: [{
      timePoint: '@time("HH:mm:ss")',
      reqCnt: '@float(1, 100, 1, 3)'
    }, {
      timePoint: '@time("HH:mm:ss")',
      reqCnt: '@float(1, 100, 1, 3)'
    }, {
      timePoint: '@time("HH:mm:ss")',
      reqCnt: '@float(1, 100, 1, 3)'
    }]
  }))
}

for (let i = 0; i < mdcount; i++) {
  mapDataList.push(Mock.mock({
    id: '@increment',
    qid: '@word(3, 5)',
    title: '@ctitle(3, 10)',
    serTrends: [{
      timePoint: '@time("HH:mm:ss")',
      reqCnt: '@float(1, 100, 1, 3)'
    }, {
      timePoint: '@time("HH:mm:ss")',
      reqCnt: '@float(1, 100, 1, 3)'
    }, {
      timePoint: '@time("HH:mm:ss")',
      reqCnt: '@float(1, 100, 1, 3)'
    }]
  }))
}

export default {
  getList: config => {
    const { city, title, page = 1, limit = 20, sort } = param2Obj(config.url)

    let mockList = List.filter(item => {
      if (city && item.city !== city) return false
      if (title && item.title.indexOf(title) < 0) return false
      return true
    })

    if (sort === '-id') {
      mockList = mockList.reverse()
    }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

    return {
      total: mockList.length,
      items: pageList
    }
  },
  getmapList: config => {
    const { city, title, limit = 3, page = 1, sort } = param2Obj(config.url)

    let mockList = mapList.filter(item => {
      if (city && item.city !== city) return false
      if (title && item.title.indexOf(title) < 0) return false
      return true
    })

    if (sort === '-id') {
      mockList = mockList.reverse()
    }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

    return {
      total: mockList.length,
      items: pageList
    }
  },
  getDataMapList: config => {
    const { city, title, limit = 20, page = 1, sort } = param2Obj(config.url)

    let mockList = mapDataList.filter(item => {
      if (city && item.city !== city) return false
      if (title && item.title.indexOf(title) < 0) return false
      return true
    })

    if (sort === '-id') {
      mockList = mockList.reverse()
    }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

    return {
      total: mockList.length,
      items: pageList
    }
  },
  product: config => {
    return {
      data: [{ name: 'PC网站', id: 33 }, { name: 'mobile网站', id: 444 }, { name: 'ios', id: 33 }, { name: 'android', id: 1024 }]
    }
  },
  monitor: config => {
    const { city, title, page = 1, limit = 20, sort } = param2Obj(config.url)

    let mockList = List.filter(item => {
      if (city && item.city !== city) return false
      if (title && item.title.indexOf(title) < 0) return false
      return true
    })

    if (sort === '-id') {
      mockList = mockList.reverse()
    }

    const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

    return {
      total: mockList.length,
      items: pageList
    }
  }
}
